#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
        sort(people.begin(), people.end(), [](const vector<int>& left, const vector<int>& right) {
            return left[0] > right[0] || (left[0] == right[0] && left[1] < right[1]);
            });
        vector<vector<int>>res;
        for (int i = 0; i < people.size(); ++i) {
            res.insert(res.begin() + people[i][1], people[i]);
        }
        return res;
    }
};